/*
 *  Copyright 2011 Arngrimur Bjarnason 
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
 

/*
Copyright 2012 Arngrimmur Bjarnason

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

/**
 * 
 */
package org.arngrimur.deviationtable.degree;


import org.arngrimur.deviationtable.IDegree;
import org.arngrimur.deviationtable.compass.Compass;

import android.view.View;
import android.view.View.OnClickListener;

/**
 * Simple class mapping of a degree. It basically wraps a {@linkplain Double}
 * It is also possible to get the value in radians.
 * 
 * @author Arngrimur Bjarnason, arngrimurbjarnason@gmail.com
 * 
 */
public abstract class AbstractDegree extends DegreeBase{
	
	/**
	 * Constructor
	 * @param degree The angle of degree on the compass in degrees. 
	 * Since no value on a compass can be less than 0 or greater than 360 the input is truncated
	 * to a value between 0 and 360.
	 * @param The compass.
	 * @see DegreeBase
	 */
	public AbstractDegree(Double degree, Compass compass) {
		super(degree % 360, compass);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(IDegree another) {
		if (another == null) {
			return 1;
		} else {
			return this.getValue().compareTo(another.getDegree());
		}
	}

	/* (non-Javadoc)
	 * @see org.arngrimur.deviationtable.IDegree#getDegree()
	 */
	@Override
	public Double getDegree() {
		return new Double(this.getValue().doubleValue());
	}

	/* (non-Javadoc)
	 * @see org.arngrimur.deviationtable.IDegree#getDegreeAsRadian()
	 */
	@Override
	public Double getDegreeAsRadian() {
		return new Double(this.getValue().doubleValue() / 180.0d * Math.PI);
	}
	
	/* (non-Javadoc)
	 * @see org.arngrimur.deviationtable.IDegree#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object o) {
		if(o == null) {
			return false;
		}
		if(o instanceof AbstractDegree) {
			return this.getValue().equals(((IDegree)o).getDegree());	
		}
		return false;	
	}
	/* (non-Javadoc)
	 * @see org.arngrimur.deviationtable.IDegree#hashCode()
	 */
	@Override
	public int hashCode() {
		return (int)this.getValue().hashCode();
	}

	/* (non-Javadoc)
	 * @see org.arngrimur.deviationtable.IDegree#toString()
	 */
	@Override
	public String toString(){
		return this.getValue().toString();
	}
	
	
	/** Gets the associated compass of this degree. */
	public final Compass getCompass() {
		return this.compass;
	}

}
